//
//  CompanyRetestViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/30.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanyRetestViewController.h"
#import "LYRetestCell.h"
#import "LYRetestCompanyModel.h"
#import "LYRetestPersonModel.h"

@interface CompanyRetestViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    NSInteger page;
}
@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation CompanyRetestViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"复试邀请";
    self.dataArray = [NSMutableArray arrayWithCapacity:0];
    page = 1;
    
    [self loadData];
    [self initUI];
}
- (void)loadData {
    self.noDataView.hidden = YES;
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:[NSString stringWithFormat:@"%ld", (long)page] forKey:@"page"];
    [dic setObject:PageSize forKey:@"number"];
    
    [BaseNetManager requestWithMethod:POST path:Resume_GetInterviewLists_URL params:dic successBlock:^(NSDictionary * _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            id data = responseObject[@"data"];
            if ([data isKindOfClass:[NSArray class]]) {
                for (NSDictionary *dic in data) {
                    PMineReexamineInviteModel *model = [[PMineReexamineInviteModel alloc] init];
                    [model setValuesForKeysWithDictionary:dic];
                    [self.dataArray addObject:model];
                }
                self.noDataView.hidden = YES;
                [self.tableview.mj_footer endRefreshing];
                [self.tableview reloadData];
            }
            if (self.dataArray.count) {
            } else {
                self.noDataView.hidden = NO;
                [self.noDataView vcNilStatusType:VCNilStatusTypeOfCommonNoData superView:self.view];
            }
            SVPHUDDismiss;
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError * _Nonnull error) {
        SVPHUDError(NetErrorAlertText);
        [self.noDataView vcNilStatusType:VCNilStatusTypeOfNoNet superView:self.view];
    }];
}
- (void)initUI {
    self.tableview = [UIToolsControl initTableViewWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-HeightOfStatusBarAndNavigationBar-SIMEmojKeyBoardkBottomNOSafeArea_Height) target:self style:UITableViewStyleGrouped];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableview.backgroundColor = COLOR_OF_WHITE;
    
    [self.tableview registerClass:[LYRetestCell class] forCellReuseIdentifier:kCellIdentifier_LYRetestCell];
    [self.view addSubview:self.tableview];
    
    __weak __typeof(self)weakSelf = self;
    self.tableview.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        self->page++;
        [weakSelf.tableview.mj_footer beginRefreshing];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(MJDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf loadData];
        });
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LYRetestCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_LYRetestCell forIndexPath:indexPath];
    if (self.isPerson) {
//        cell.personModel = self.dataArray[indexPath.section];
    } else {
//        cell.companyModel = self.dataArray[indexPath.section];
        PMineReexamineInviteModel *model = self.dataArray[indexPath.section];
        [cell reloadDataForCompanyModel:model];
    }
    return cell;
}

#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.isPerson) {
        LYRetestPersonModel *model = self.dataArray[indexPath.section];
        if (model.notes.length) {
            return 270;
        } else {
            return 250;
        }
    } else {
        return 250.0;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    PMineReexamineInviteModel *model = self.dataArray[section];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = THEMECOLOR_OF_TEXT_9a9a9a;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = model.add_timeYYYYMMddHHmm;
    label.font = Font(Font_13);
    return label;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001f;
}

@end
